{include file="public/header" /}

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <fieldset id="searchFieldset_currentTableRenderId" class="table-search-fieldset">
                        <legend>条件搜索</legend>
                        <form class="layui-form layui-form-pane form-search">
                            <div class="layui-form-item layui-inline">
                                <label class="layui-form-label">商品搜索</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="title" placeholder="商品名称(模糊搜索)"
                                        value="{:input('get.title')}" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item layui-inline">
                                <label class="layui-form-label">项目类型</label>
                                <div class="layui-input-inline">
                                    <select name="type">
                                        <option value="">请选择项目类型</option>
                                        <option value="1" {if !empty(input('get.type')) &&
                                            input('get.type')==1}selected{/if}>技术服务</option>
                                        <option value="2" {if !empty(input('get.type')) &&
                                            input('get.type')==2}selected{/if}>配送服务</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item layui-inline">
                                <label class="layui-form-label">平台大分类</label>
                                <div class="layui-input-inline">
                                    <select name="platclassid" lay-filter="platclassid">
                                        <option value="">请选择所属分类</option>
                                        {foreach $platclass as $v}
                                        <option value="{$v.id}" {if !empty(input('get.platclassid')) &&
                                            input('get.platclassid')==$v.id}selected{/if}>
                                            {$v.name}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item layui-inline">
                                <label class="layui-form-label">平台分类</label>
                                <div class="layui-input-inline">
                                    <select name="sonsid">
                                        <option value="">请选择所属分类</option>
                                        {foreach $ptsons as $v}
                                        <option value="{$v.id}" {if !empty(input('get.sonsid')) &&
                                            input('get.sonsid')==$v.id}selected{/if}>
                                            {$v.name}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item layui-inline">
                                <label class="layui-form-label">商家</label>
                                <div class="layui-input-inline">
                                    <select name="businessid" lay-filter="businessid" lay-search>
                                        <option value="">请选择搜索商家</option>
                                        {foreach $shop as $v}
                                        <option value="{$v.id}" {if !empty(input('get.businessid')) &&
                                            input('get.businessid')==$v.id}selected{/if}>{$v.title}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item layui-inline">
                                <label class="layui-form-label">服务省份</label>
                                <div class="layui-input-inline">
                                    <select name="province" lay-filter="province">
                                        <option value="">请选择搜索管理省份</option>
                                        {foreach $province as $v}
                                        <option value="{$v.area_code}" {if !empty(input('get.province')) &&
                                            input('get.province')==$v.area_code}selected{/if}>{$v.name}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item layui-inline">
                                <label class="layui-form-label">服务城市</label>
                                <div class="layui-input-inline">
                                    <select name="city" lay-filter="city">
                                        <option value="">请选择搜索管理城市</option>
                                        {foreach $city as $v}
                                        <option value="{$v.area_code}" {if !empty(input('get.city')) &&
                                            input('get.city')==$v.area_code}selected{/if}>{$v.name}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item layui-inline">
                                <label class="layui-form-label">服务区域</label>
                                <div class="layui-input-inline">
                                    <select name="area" lay-filter="area">
                                        <option value="">请选择搜索管理区域</option>
                                        {foreach $area as $v}
                                        <option value="{$v.area_code}" {if !empty(input('get.area')) &&
                                            input('get.area')==$v.area_code}selected{/if}>{$v.name}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item layui-inline">
                                <label class="layui-form-label">服务街道</label>
                                <div class="layui-input-inline">
                                    <select name="street" lay-filter="street">
                                        <option value="">请选择搜索管理街道</option>
                                        {foreach $street as $v}
                                        <option value="{$v.id}" {if !empty(input('get.street')) &&
                                            input('get.street')==$v.id}selected{/if}>{$v.name}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item layui-inline">
                                <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="sreach">搜索</button>
                            </div>
                        </form>
                    </fieldset>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn layui-bg-cyan layui-btn-sm"
                        onclick="open_add('添加','goodslist_edit?businessid={:input('get.businessid')}')"><i
                            class="layui-icon">&#xe654;</i>添加</button>&nbsp;
                    {if !empty(input('get.businessid'))}
                    <a title="快速导入项目"
                        onclick="open_add('快速导入项目','/system/goodslist?business={:input('get.businessid')}')"
                        href="javascript:;" class="layui-btn layui-btn-normal layui-btn-sm">
                        快速导入项目
                    </a>
                    {/if}
                    共有数据：<strong id="count">{$list->total()}</strong> 条
                </div>
                <div class="layui-table-body layui-table-main">
                    <table class="layui-table layui-form">
                        <thead>
                            <tr>
                                <th>
                                    <div class="layui-table-cell">ID</div>
                                </th>
                                <th>
                                    <div class="layui-table-cell">项目类型</div>
                                </th>
                                <th>
                                    <div class="layui-table-cell">商品名称</div>
                                </th>
                                <th>
                                    <div class="layui-table-cell">默认规格</div>
                                </th>
                                <th>
                                    <div class="layui-table-cell">商家名称</div>
                                </th>
                                <th>
                                    <div class="layui-table-cell">商品图册</div>
                                </th>
                                <th>
                                    <div class="layui-table-cell">所属分类</div>
                                </th>
                                <th>
                                    <div class="layui-table-cell">销量</div>
                                </th>
                                <th>
                                    <div class="layui-table-cell">状态</div>
                                </th>
                                <th>
                                    <div class="layui-table-cell">操作</div>
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            {foreach $list as $v}
                            <tr>
                                <td>
                                    <div class="layui-table-cell">{$v.id|default=''}</div>
                                </td>
                                <td>
                                    <div class="layui-table-cell">{if $v.type == 1}技术服务{elseif $v.type == 2}配送服务{/if}
                                    </div>
                                </td>
                                <td>
                                    <div class="layui-table-cell">{$v.title|default=''}</div>
                                </td>
                                <td>
                                    <div class="layui-table-cell">
                                        规格名:{$v.goodspec.name|default='无规格'}
                                        单价:{$v.goodspec.price|default='0'}元/{$v.goodspec.unmit|default='件'}
                                    </div>
                                </td>
                                <td>
                                    <div class="layui-table-cell">{$v.shopname|default=''}</div>
                                </td>
                                <td>
                                    <div id="layer-photos-demo" class="layer-photos-demo">
                                        {foreach $v.images as $k=> $vs}
                                        <img layer-pid="" style="height: 40px;" layer-src="{$vs|default=''}"
                                            src="{$vs|default=''}" alt="{$v.title|default=''}">
                                        {/foreach}
                                    </div>
                                </td>
                                <td>
                                    <div class="layui-table-cell">{$v.class_name|default=''}|{$v.sons_name|default=''}
                                    </div>
                                </td>
                                <td>
                                    <div class="layui-table-cell">{$v.sale|default=''}</div>
                                </td>
                                <td>
                                    <div class="layui-table-cell">{if $v.isSale == 1}上架{else}下架{/if}</div>
                                </td>
                                <td class="td-manage">
                                    <div class="layui-table-cell">
                                        <a title="操作" onclick="open_add('操作','/shop/goodslist_edit?id={$v.id}')"
                                            href="javascript:;" class="layui-btn layui-btn-sm">
                                            操作
                                        </a>
                                        <a title="评论列表" onclick="open_add('评论列表','/shop/compent?id={$v.id}')"
                                            href="javascript:;" class="layui-btn layui-btn-normal layui-btn-sm">
                                            评论列表
                                        </a>
                                        <a title="删除" onclick="open_dels(this,'/shop/goodslist_del','{$v.id}')"
                                            href="javascript:;" class="layui-btn-danger layui-btn layui-btn-sm">
                                            删除
                                        </a>
                                    </div>
                                </td>
                            </tr>
                            {/foreach}

                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body">
                    <div class="page">
                        {$list->render()|raw}
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>
{include file="public/footer"}
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;
        //监听省份选择
        form.on('select(province)', function (data) {
            if (!data.value) {
                $('select[name="city"]').html('');
                $('select[name="area"]').html('');
                $('select[name="street"]').html('');
                form.render();
                return false;
            }
            //发异步，把数据提交给php
            $.ajax({
                type: 'get',
                url: '/base/getregion',
                data: { area_code: data.value, level: 2 },
                success: function (res) {
                    if (res.status == 0) {
                        var str = '<option value="">请选择城市</option>';
                        $.each(res.data, function (i, obj) {
                            str += '<option value="' + obj.area_code;
                            str += '">' + obj.name;
                            str += '</option>';
                        });
                        $('select[name="city"]').html(str);
                        $('select[name="area"]').html('');
                        $('select[name="street"]').html('');
                        form.render();
                    } else {
                        layer.msg(res.msg, { icon: 2, time: 1000 });
                    }
                }
            });
            return false;
        });
        //监听城市选择
        form.on('select(city)', function (data) {
            if (!data.value) {
                $('select[name="area"]').html('');
                $('select[name="street"]').html('');
                form.render();
                return false;
            }
            //发异步，把数据提交给php
            $.ajax({
                type: 'get',
                url: '/base/getregion',
                data: { area_code: data.value, level: 3 },
                success: function (res) {
                    if (res.status == 0) {
                        var str = '<option value="">请选择区域</option>';
                        $.each(res.data, function (i, obj) {
                            str += '<option value="' + obj.area_code;
                            str += '">' + obj.name;
                            str += '</option>';
                        });
                        $('select[name="area"]').html(str);
                        $('select[name="street"]').html('');
                        form.render();
                    } else {
                        layer.msg(res.msg, { icon: 2, time: 1000 });
                    }
                }
            });
            return false;
        });
        //监听区域选择
        form.on('select(area)', function (data) {
            if (!data.value) {
                $('select[name="street"]').html('');
                form.render();
                return false;
            }
            //发异步，把数据提交给php
            $.ajax({
                type: 'get',
                url: '/base/getregion',
                data: { area_code: data.value, level: 4 },
                success: function (res) {
                    if (res.status == 0) {
                        var str = '<option value="">请选择街道</option>';
                        $.each(res.data, function (i, obj) {
                            str += '<option value="' + obj.id;
                            str += '">' + obj.name;
                            str += '</option>';
                        });
                        $('select[name="street"]').html(str);
                        form.render();
                    } else {
                        layer.msg(res.msg, { icon: 2, time: 1000 });
                    }
                }
            });
            return false;
        });
        //监听分类 
        form.on('select(platclassid)', function (data) {
            if (!data.value) {
                $('select[name="sonsid"]').html('');
                form.render();
                return false;
            }
            //发异步，把数据提交给php
            $.ajax({
                type: 'get',
                url: '/base/getsons',
                data: { classid: data.value },
                success: function (res) {
                    if (res.status == 0) {
                        var str = '<option value="">请选择分类</option>';
                        $.each(res.data, function (i, obj) {
                            console.log(obj);
                            str += '<option value="' + obj.id;
                            str += '">' + obj.name;
                            str += '</option>';
                        });
                        $('select[name="sonsid"]').html(str);
                        form.render();
                    } else {
                        layer.msg(res.msg, { icon: 2, time: 1000 });
                    }
                }
            });
            return false;
        });
    });
</script>
</body>